﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Twitterizer;

namespace Twillo.Core.Controls
{
    public partial class UserProfile : UserControlBase
    {
        [Category("Twitter")]
        public TwitterUser TwitterUser { get { return _user; } set { _user = value; RefreshControl(); } }

        private TwitterUser _user = null;


        public UserProfile()
        {
            InitializeComponent();
        }

        private void RefreshControl()
        {
            ToolTip tip = new ToolTip();
            tip.SetToolTip(this, "");
            lblScreenName.Text = "";
            lblDescription.Text = "";
            lnkWebSite.Text = "";
            lnkWebSite.Tag = "";
            pbIcon.Image = EmptyImage();

            if (this.DesignMode) { return; }
            if (_user == null) { return; }

            //this.tableLayoutPanel1.BackColor = _user.ProfileSidebarBorderColor;
            //this.BackColor = _user.ProfileBackgroundColor;
            //this.ForeColor = _user.ProfileTextColor;
            //_user.ProfileLinkColor;
            //_user.ProfileSidebarBorderColor;

            this.pbFollowing.Image = Twillo.Core.Properties.Resources.no;
            this.pbGeoEnabled.Image = Twillo.Core.Properties.Resources.no;
            this.pbProtected.Image = Twillo.Core.Properties.Resources.no;

            if (_user.IsFollowing.HasValue)
            {
                this.pbFollowing.Image = (_user.IsFollowing.Value) ? Twillo.Core.Properties.Resources.ok : Twillo.Core.Properties.Resources.no;
            }

            if (_user.IsGeoEnabled.HasValue)
            {
                this.pbGeoEnabled.Image = (_user.IsGeoEnabled.Value) ? Twillo.Core.Properties.Resources.ok : Twillo.Core.Properties.Resources.no;
            }

            lblTimeZone.Text = _user.TimeZone;
            lblCreatedDate.Text = "";

            if (_user.CreatedDate.HasValue)
            {
                lblCreatedDate.Text = _user.CreatedDate.Value.ToLongDateString() + " " + _user.CreatedDate.Value.ToShortTimeString();
            }
            this.pbProtected.Image = (_user.IsProtected) ? Twillo.Core.Properties.Resources.ok : Twillo.Core.Properties.Resources.no;
            lblFavorites.Text = _user.NumberOfFavorites.ToString();
            lblFollowers.Text = _user.NumberOfFollowers.ToString();
            lblFriends.Text = _user.NumberOfFriends.ToString();
            lblStates.Text = _user.NumberOfStatuses.ToString();

            if (!string.IsNullOrEmpty(_user.Website))
            {
                lnkWebSite.Text = _user.Website;
                lnkWebSite.Tag = _user.Website;
            }

            pbVerified.Visible = false;

            if (_user.Verified.HasValue)
            {
                pbVerified.Visible = _user.Verified.Value;
                tip.SetToolTip(pbVerified, "Verified");
            }
            pbIcon.Image = LoadImage(_user.ProfileImageLocation);
            lblScreenName.Text = _user.ScreenName;
            lblDescription.Text = _user.Description;
            if (!string.IsNullOrEmpty(_user.Location)) { lblDescription.Text += "\nLocated In " + _user.Location; }
            tip.SetToolTip(this, _user.Description);
        }


    }
}
